package lambdasinaction.chap10;

import java.util.*;

public class OptionalMain {

    public String getCarInsuranceName(Optional<Person> person) {
        final Optional<Car> car = person.flatMap(Person::getCar);
        final Optional<Optional<Car>> car1 = person.map(Person::getCar);


        return person.flatMap(Person::getCar)
                     .flatMap(Car::getInsurance)
                     .map(Insurance::getName)
                     .orElse("Unknown");
    }

    public static void main(String[] args) {
        final Person person = null;
//        System.out.println(Optional.ofNullable(person).flatMap(Person::getCar).flatMap(Car::getInsurance).map(Insurance::getName).orElse("aa"));
        final String fff = Optional.ofNullable(person).map(Person::getName).orElse("fff");
        System.out.println(fff);
    }
}
